package com.link.play.fit.ai.ui.guide.ac

import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.content.Intent
import android.media.MediaPlayer
import android.os.Bundle
import androidx.core.animation.addListener
import com.link.play.fit.ai.R
import com.link.play.fit.ai.base.BaseActivity
import com.link.play.fit.ai.databinding.AcGuideHelloBinding
import com.link.play.fit.ai.ext.setThrottleListener
import com.link.play.fit.ai.kv.AuthCache.isGuideHello
import com.link.play.fit.ai.utils.ScreenUtil.Companion.dpToPx


class GuideHelloAc : BaseActivity<AcGuideHelloBinding>(AcGuideHelloBinding::inflate) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        animation()

        binding.tvBtn.setThrottleListener {
            isGuideHello = true
//            val mediaPlayer: MediaPlayer? = MediaPlayer.create(this, R.raw.scan)
//            if (mediaPlayer != null) {
//                startActivity(Intent(this, GuideVideoAc::class.java))
//            } else {
            startActivity(Intent(this, GuidePbAc::class.java))
//            }
            overridePendingTransition(R.anim.fade_in, R.anim.fade_out)
            finish()
        }
    }

    private fun animation() {

        val scaleAnimatorX = ObjectAnimator.ofFloat(binding.ivRen, "scaleX", 0.0f, 1.0f)
        val scaleAnimatorY = ObjectAnimator.ofFloat(binding.ivRen, "scaleY", 0.0f, 1.0f)
        val animatorImage = ObjectAnimator.ofFloat(binding.ivRen, "alpha", 0.0f, 1.0f)
        animatorImage.duration = 250

        scaleAnimatorX.duration = 500 // 动画持续时间（毫秒）
        scaleAnimatorY.duration = 500 // 动画持续时间（毫秒）

        // 使用 AnimatorSet 同时播放两个动画
        val animatorSetXY = AnimatorSet()
        animatorSetXY.playTogether(animatorImage, scaleAnimatorX, scaleAnimatorY)


        val offset = dpToPx(60f)
        binding.ll1.translationY = offset
        val animator1 = ObjectAnimator.ofFloat(binding.ll1, "translationY", offset, 0f)
        animator1.duration = 500 // 动画持续时间（毫秒）
        val animator2 = ObjectAnimator.ofFloat(binding.ll1, "alpha", 0.1f, 1.0f)
        animator2.duration = 250 // 动画持续时间（毫秒）
        val animator3 = ObjectAnimator.ofFloat(binding.ll1, "alpha", 1.0f, 0.0f)
        animator3.duration = 300 // 动画持续时间（毫秒）


        binding.tv3.translationY = offset
        val animator4 = ObjectAnimator.ofFloat(binding.tv3, "translationY", offset, 0f)
        animator1.duration = 500 // 动画持续时间（毫秒）
//
        val animator5 = ObjectAnimator.ofFloat(binding.tv3, "alpha", 0.1f, 1.0f)
        animator2.duration = 500 // 动画持续时间（毫秒）

        val animator6 = ObjectAnimator.ofFloat(binding.tvBtn, "alpha", 0.0f, 1.0f)
        animator2.duration = 500 // 动画持续时间（毫秒）


        val animatorSet = AnimatorSet()
        animatorSet.playTogether(animator1, animator2, animatorSetXY)
        animatorSet.play(animator3).after(1100)

        animatorSet.play(animator4).after(1400)
        animatorSet.play(animator5).after(1400)

        animatorSet.play(animator6).after(2200)

        animatorSet.addListener(onEnd = {
            binding.tvBtn.isEnabled = true
        })
        animatorSet.start()


    }


}